package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;

    @Override
    public String add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClueTrackRecord tbClueTrackRecord1 = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord, tbClueTrackRecord1);
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        Date date = new Date();

        tbClueTrackRecord1.setCreateTime(date);
        tbClueTrackRecordMapper.add(tbClueTrackRecord1);
        Long clueId = tbClueTrackRecord.getClueId();
        //根据ID查询出这条数据所有内容
        TbClue tbClue = tbClueMapper.selectTbClueById(clueId);
        //进行修改
        tbClue.setQq(tbClueTrackRecord.getQq());
        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
        tbClue.setAge(tbClueTrackRecord.getAge());
        tbClue.setName(tbClueTrackRecord.getName());
        tbClue.setSex(tbClueTrackRecord.getSex());

        tbClueMapper.updateTbClue(tbClue);

//        TbClue tbClue = new TbClue();
//        tbClue.setId(clueId);
//        tbClue.setSex(tbClueTrackRecord.getSex());
//        tbClue.setName(tbClueTrackRecord.getName());
//        tbClue.setAge(tbClueTrackRecord.getAge());
//        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
//        tbClue.setQq(tbClueTrackRecord.getQq());

//        tbClueTrackRecordMapper.update(tbClueTrackRecord);

        return "操作成功";
    }

    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        List<TbClueTrackRecord> list = tbClueTrackRecordMapper.list(clueId);
        return list;
    }
}
